package cn.codeforfun.goods;

import com.fasterxml.jackson.databind.JsonMappingException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;


/**
 * Created by Administrator on 2016/12/18 0018.
 */
@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @RequestMapping("/list")
    @ResponseBody
    public Page<Goods> list(@RequestBody Map map) {
        PageRequest pageRequest = new PageRequest((int) map.get("number"), (int) map.get("size"));
        return goodsService.goodsPage(pageRequest);
    }

    @RequestMapping("/detail")
    @ResponseBody
    public Goods detail(Integer id) {
        return goodsService.findOne(id);
    }
}
